/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Merlion.MRP.entity;

import Merlion.SCM.entity.ProductEntity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import org.apache.commons.lang3.StringUtils;

@Entity
public class MonthlySalesRecordEntity implements Serializable {

    //@ManyToOne
    //private AnnualSalesRecordEntity annualSalesRecordEntity;
    @Id
    private String id; //prodId-MMYYYY
    private Integer monthInt;
    private Integer yearInt;
    private int actualSales;
    private int actualPromotion;
    private int actualBase;
    private int projectedSales;
    private int projectedPromotion;
    private int projectedBase;
    private int ratio; // ratio/100 of the monthly sales record
    @ManyToOne
    private ProductEntity product;
    @OneToOne
    private PlannedMonthlyDemandEntity plannedMonthlyDemand;
    //@OneToMany(mappedBy = "monthlySalesRecord")
    //private List<MonthlySalesRecordProductBreakdownEntity> monthlySalesRecordProductBreakdownEntities;
    private boolean converted;
    @ManyToOne
    private ConsolidatedMonthlySalesRecordEntity consolidatedMonthlySalesRecordEntity;

    public MonthlySalesRecordEntity() {
        this.converted = false;
    }

    public MonthlySalesRecordEntity(ProductEntity pdt, Integer yearInt, Integer monthInt) {
        String stringId = StringUtils.leftPad(pdt.getId().toString(), 4, "0") + "/" + yearInt.toString() + StringUtils.leftPad(monthInt.toString(), 2, "0");
        this.id = stringId;
        this.yearInt = yearInt;
        this.monthInt = monthInt;
        this.product = pdt;
        this.converted = false;
    }
    /*
    public MonthlySalesRecordEntity(AnnualSalesRecordEntity annualSalesRecord, Integer monthInt) {
    String idString = StringUtils.leftPad(monthInt.toString(), 2, "0") + annualSalesRecord.getYearOfSales().toString();
    this.id = idString;
    this.annualSalesRecordEntity = annualSalesRecord;
    this.yearInt = annualSalesRecord.getYearOfSales();
    this.monthInt = monthInt;
    this.converted = false;
    }*/

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public ProductEntity getProduct() {
        return product;
    }

    public void setProduct(ProductEntity product) {
        this.product = product;
    }

    public Integer getMonthInt() {
        return monthInt;
    }

    public void setMonthInt(Integer monthInt) {
        this.monthInt = monthInt;
    }

    public Integer getYearInt() {
        return yearInt;
    }

    public void setYearInt(Integer yearInt) {
        this.yearInt = yearInt;
    }
    /*
    public AnnualSalesRecordEntity getAnnualSalesRecordEntity() {
    return annualSalesRecordEntity;
    }
    
    public void setAnnualSalesRecordEntity(AnnualSalesRecordEntity annualSalesRecordEntity) {
    this.annualSalesRecordEntity = annualSalesRecordEntity;
    }
     */

    public int getActualBase() {
        return actualBase;
    }

    public void setActualBase(int actualBase) {
        this.actualBase = actualBase;
    }

    public int getActualPromotion() {
        return actualPromotion;
    }

    public void setActualPromotion(int actualPromotion) {
        this.actualPromotion = actualPromotion;
    }

    public int getActualSales() {
        return actualSales;
    }

    public void setActualSales(int actualSales) {
        this.actualSales = actualSales;
    }

    public int getProjectedBase() {
        return projectedBase;
    }

    public void setProjectedBase(int projectedBase) {
        this.projectedBase = projectedBase;
    }

    public int getProjectedPromotion() {
        return projectedPromotion;
    }

    public void setProjectedPromotion(int projectedPromotion) {
        this.projectedPromotion = projectedPromotion;
    }

    public int getProjectedSales() {
        return projectedSales;
    }

    public void setProjectedSales(int projectedSales) {
        this.projectedSales = projectedSales;
    }

    public PlannedMonthlyDemandEntity getPlannedMonthlyDemand() {
        return plannedMonthlyDemand;
    }

    public void setPlannedMonthlyDemand(PlannedMonthlyDemandEntity plannedMonthlyDemand) {
        this.plannedMonthlyDemand = plannedMonthlyDemand;
    }
/*
    public List<MonthlySalesRecordProductBreakdownEntity> getMonthlySalesRecordProductBreakdownEntities() {
        return monthlySalesRecordProductBreakdownEntities;
    }

    public void setMonthlySalesRecordProductBreakdownEntities(List<MonthlySalesRecordProductBreakdownEntity> monthlySalesRecordProductBreakdownEntities) {
        this.monthlySalesRecordProductBreakdownEntities = monthlySalesRecordProductBreakdownEntities;
    }

     * 
     */
    public boolean isConverted() {
        return converted;
    }

    public void setConverted(boolean converted) {
        this.converted = converted;
    }

    public ConsolidatedMonthlySalesRecordEntity getConsolidatedMonthlySalesRecordEntity() {
        return consolidatedMonthlySalesRecordEntity;
    }

    public void setConsolidatedMonthlySalesRecordEntity(ConsolidatedMonthlySalesRecordEntity consolidatedMonthlySalesRecordEntity) {
        this.consolidatedMonthlySalesRecordEntity = consolidatedMonthlySalesRecordEntity;
    }

    public int getRatio() {
        return ratio;
    }

    public void setRatio(int ratio) {
        this.ratio = ratio;
    }

    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MonthlySalesRecordEntity)) {
            return false;
        }
        MonthlySalesRecordEntity other = (MonthlySalesRecordEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "mrp.entities.MonthlySalesRecord[ id=" + id + " ]";
    }
}
